package org.example.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface CounterMapper {
    @Select("""
            SELECT count(*)
            FROM db_account AS a
            INNER JOIN rs_account_forum AS b
            ON a.id = b.uid
            INNER JOIN db_forum AS c
            ON c.id = b.fid
            WHERE a.id = #{userID} AND b.type = 'release'""")
    Integer getMyReleaseForumCountByUserID(@Param("userID") Integer userID);

    @Select("""
            SELECT count(*)
            FROM db_account AS a
            INNER JOIN rs_account_forum AS b
            ON a.id = b.uid
            INNER JOIN db_forum AS c
            ON c.id = b.fid
            WHERE a.id = #{userID} AND b.type = 'follow'
            """)
    Integer getMyFollowForumCountByUserID(@Param("userID") Integer userID);

    @Select("""
            SELECT count(*)
            FROM db_account AS a
            INNER JOIN rs_history AS b
            ON a.id = b.uid
            INNER JOIN db_post AS c
            ON c.id = b.pid
            WHERE a.id = #{userID}
            """)
    Integer getMyHistoryCountByUserID(@Param("userID") Integer userID);

    @Select("""
            SELECT count(*)
            FROM db_account AS a
            INNER JOIN rs_account_message AS b
            ON a.id = b.uid
            INNER JOIN db_message AS c
            ON c.id = b.mid
            WHERE b.type = 'follow' AND a.id = #{userID}
            """)
    Integer getMyFollowMessageCountByUserID(@Param("userID") Integer userID);

    @Select("""
            SELECT b.exp , b.a_describe
            FROM db_account AS a
            INNER JOIN db_account_extend AS b
            ON a.id = b.uid
            WHERE a.id = #{userID}
            """)
    Map<String, Object> getMyEXPAndDescribeByUserID(@Param("userID") Integer userID);
    @Select("""
            SELECT b.icon
            FROM db_account AS a
            INNER JOIN db_account_extend AS b
            ON a.id = b.uid
            WHERE a.id = #{userID}
            """)
    String getIconPathByUserID(@Param("userID") Integer userID);

}
